package cn.iocoder.yudao.module.xkfz.controller.admin.excel;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.xkfz.controller.admin.excel.result.CommonExcelResult;
import cn.iocoder.yudao.module.xkfz.domain.excel.entity.AchievementAward;
import cn.iocoder.yudao.module.xkfz.domain.excel.entity.TechnologicalOutputSci;
import cn.iocoder.yudao.module.xkfz.domain.excel.po.AchievementAwardPo;
import cn.iocoder.yudao.module.xkfz.group.ImportGroup;
import cn.iocoder.yudao.module.xkfz.service.excel.AchievementAwardService;
import cn.iocoder.yudao.module.xkfz.util.ExcelHeaderExtractor;
import cn.iocoder.yudao.module.xkfz.util.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * @Description 成果奖项
 * @Author ZWC
 * @Date 2024/5/13 13:38
 */
@RestController
@RequestMapping("achievementAward")
public class AchievementAwardController {

    @Autowired
    private AchievementAwardService achievementAwardService;

    @PostMapping("importAchievementAward")
    public CommonResult<Boolean> importAchievementAward(@RequestParam("file") MultipartFile file, @RequestParam("year") String year
            , @RequestParam("indexId") String indexId) throws IOException {
        List<AchievementAward> list = ExcelUtils.read(file, AchievementAward.class);

        ValidationUtil.validate(list, ImportGroup.class);
        return success(achievementAwardService.importAchievementAward(list, year, indexId));
    }

    @GetMapping("selectPage")
    public CommonExcelResult<PageResult<AchievementAward>> selectPage (AchievementAwardPo reqVO){
        List<HashMap<String, String>> headerList = ExcelHeaderExtractor.getHeaderList(AchievementAward.class);
        return CommonExcelResult.success(achievementAwardService.selectPage(reqVO),headerList);
    }
    @PostMapping("insert")
    public CommonResult<Boolean> insert(AchievementAward achievementAward){
        return success(achievementAwardService.insert(achievementAward));
    }
    @PostMapping("update")
    public CommonResult<Boolean> update(AchievementAward achievementAward){
        return success(achievementAwardService.update(achievementAward));
    }

    @PostMapping("delete")
    public CommonResult<Boolean> delete(String id){
        return success(achievementAwardService.delete(id));
    }
}
